<template>
  <div class="dashboard-page">
    <div class="page-header">
      数据统计
    </div>

    <div class="stats-cards" v-loading="isloading">
      <!-- 总模块数卡片 -->
      <div class="stat-card">
        <div class="card-content">
          <div class="card-text">
            <h3 class="card-title">总模块数</h3>
            <div class="card-value">{{ dataCount?.moduleCount ?? '-' }}</div>
          </div>
          <div class="card-icon modules-icon">
            <i class="icon-modules">📊</i>
          </div>
        </div>
      </div>

      <!-- 总API数卡片 -->
      <div class="stat-card">
        <div class="card-content">
          <div class="card-text">
            <h3 class="card-title">总API数</h3>
            <div class="card-value">{{ dataCount?.apiCount ?? '-' }}</div>
          </div>
          <div class="card-icon api-icon">
            <i class="icon-api">&lt;/&gt;</i>
          </div>
        </div>
      </div>

      <!-- 项目成员卡片 -->
      <div class="stat-card">
        <div class="card-content">
          <div class="card-text">
            <h3 class="card-title">项目成员</h3>
            <div class="card-value">{{ formatNumber(Number(dataCount?.memberCount)) || '-' }}</div>
          </div>
          <div class="card-icon members-icon">
            <i class="icon-members">👥</i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { getDataStatistics } from '@/common/apis/project/index.ts';
import { useRoute } from 'vue-router';

const dataCount = ref({});
const isloading = ref(false);
const route = useRoute();

function formatNumber(num) {
  return num.toLocaleString();
}

onMounted(async () => {
  try {
    isloading.value = true;
    const { data } = await getDataStatistics({ id: Number(route.params.id) });
    dataCount.value = data;
  } catch (error) {
  } finally {
    isloading.value = false;
  }

});
</script>

<style lang="less" scoped>
.dashboard-page {
  padding: 16px;
  background: var(--bg-primary);
  min-height: 100vh;

  .page-header {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;

    h2 {
      margin: 0 0 8px 0;
      font-size: 28px;
      font-weight: 600;
      color: var(--text-primary);
    }

    p {
      margin: 0;
      font-size: 16px;
      color: var(--text-secondary);
    }
  }

  .stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    max-width: 1200px;

    .stat-card {
      background: var(--card-bg);
      border: 1px solid var(--border-light);
      border-radius: 12px;
      padding: 24px;
      box-shadow: var(--shadow-light);
      transition: all 0.3s ease;
      position: relative;
      overflow: hidden;

      &:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-medium);
        border-color: var(--primary-color);
      }

      .card-content {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        position: relative;
        z-index: 2;

        .card-text {
          flex: 1;

          .card-title {
            margin: 0 0 12px 0;
            font-size: 16px;
            font-weight: 500;
            color: var(--text-primary);
            line-height: 1.4;
          }

          .card-value {
            font-size: 36px;
            font-weight: 700;
            color: var(--text-primary);
            line-height: 1;
            margin: 0;
          }
        }

        .card-icon {
          width: 48px;
          height: 48px;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          background: var(--bg-secondary);
          color: var(--primary-color);
          font-size: 18px;
        }
      }

      // 卡片背景装饰
      &::before {
        content: '';
        position: absolute;
        top: -50%;
        right: -50%;
        width: 100%;
        height: 100%;
        background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
        transform: rotate(45deg);
        z-index: 1;
      }
    }
  }

  // 响应式设计
  @media (max-width: 768px) {
    padding: 16px;

    .stats-cards {
      grid-template-columns: 1fr;
      gap: 16px;

      .stat-card {
        padding: 20px;

        .card-content {
          .card-text {
            .card-value {
              font-size: 28px;
            }
          }

          .card-icon {
            width: 40px;
            height: 40px;
            font-size: 16px;
          }
        }
      }
    }
  }

  @media (max-width: 480px) {
    .page-header {
      h2 {
        font-size: 24px;
      }

      p {
        font-size: 14px;
      }
    }

    .stats-cards {
      .stat-card {
        .card-content {
          .card-text {
            .card-title {
              font-size: 14px;
            }

            .card-value {
              font-size: 24px;
            }
          }

          .card-icon {
            width: 36px;
            height: 36px;
            font-size: 14px;
          }
        }
      }
    }
  }
}
</style>